package com.project.server.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.server.common.api.Result;
import com.project.server.service.ArticleCategoryService;
import com.project.server.entity.ArticleCategory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/article/category")
public class ArticleCategoryController {

    @Autowired
    private ArticleCategoryService categoryService;

    @GetMapping("/list")
    public Result<IPage<ArticleCategory>> list(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String name,
            @RequestParam(required = false) Integer status) {
        return Result.success(categoryService.page(current, size, name, status));
    }


    @PostMapping
    public Result<Boolean> add(@RequestBody ArticleCategory category) {
        return Result.success(categoryService.save(category));
    }

    @PostMapping("/update")
    public Result<Boolean> update(@RequestBody ArticleCategory category) {
        return Result.success(categoryService.updateById(category));
    }

    @DeleteMapping("/{id}")
    public Result<Boolean> delete(@PathVariable Long id) {
        return Result.success(categoryService.removeById(id));
    }
}
